package com.cykj.page01.servlet;

import com.alibaba.fastjson2.JSON;
import com.cykj.page01.MyHttpRequest;
import com.cykj.page01.MyHttpResponse;
import com.cykj.page01.anno.ServletMapping;
import com.cykj.page01.dto.ResponseDTO;
import com.cykj.page01.service.impl.UserServiceImpl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @BelongsProject: HandTomcat
 * @BelongsPackage: com.cykj.page02.servlet
 * @Author: 阿隆
 * @CreateTime: 2025-10-25 11:36
 * @Description: TODO
 * @Version: 1.0
 */
@ServletMapping("/login")
public class LoginServlet extends BaseServlet {

    @Override
    public void doGet(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {
        //获取账号密码 参数
        String account = httpRequest.getRequestParamToKey("account");
        String password = httpRequest.getRequestParamToKey("password");

        //创建业务层实例
      //  UserServiceImpl userService = new UserServiceImpl();
        //调用方法
        ResponseDTO dto = UserServiceImpl.getInstance().login(account, password);
        //写出数据
        httpResponse.write(JSON.toJSONBytes(dto));

    }


    @Override
    public void doPost(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {
        doGet(httpRequest, httpResponse);
    }


}